<template>
  <div class="breadcrumb-container" :class="[type, size]">
    <div class="breadcrumb-main">
      <el-breadcrumb :separator="separator" class="beauty-breadcrumb">
        <el-breadcrumb-item 
          v-for="(item, index) in items" 
          :key="index"
          :to="item.to"
          :class="{ 'active': index === items.length - 1 }"
        >
          <el-icon v-if="item.icon">
            <component :is="item.icon" />
          </el-icon>
          <span>{{ item.label }}</span>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    
    <div v-if="showExtra" class="breadcrumb-extra">
      <slot name="extra">
        <el-tag v-if="tagContent" :type="tagType" size="small">
          {{ tagContent }}
        </el-tag>
        <el-button 
          v-if="showRefresh" 
          type="primary" 
          link 
          size="small"
          @click="handleRefresh"
        >
          <el-icon><i-ep-refresh /></el-icon>
          刷新
        </el-button>
      </slot>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { PropType } from 'vue'
import type { Component } from 'vue'

interface BreadcrumbItem {
  label: string
  to?: string
  icon?: Component
}

const props = withDefaults(defineProps<{
  // 面包屑项数据
  items: BreadcrumbItem[]
  // 分隔符
  separator?: string
  // 样式类型
  type?: 'gradient' | 'card' | 'modern' | 'icon'
  // 尺寸
  size?: 'small' | 'medium' | 'large'
  // 是否显示额外内容区域
  showExtra?: boolean
  // 标签内容
  tagContent?: string
  // 标签类型
  tagType?: string
  // 是否显示刷新按钮
  showRefresh?: boolean
}>(), {
  items: () => [],
  separator: '/',
  type: 'modern',
  size: 'medium',
  showExtra: false,
  tagContent: '',
  tagType: 'info',
  showRefresh: false
})

const emit = defineEmits<{(e: 'refresh'): void}>()

const handleRefresh = () => {
  emit('refresh')
}
</script>

<style scoped>
.breadcrumb-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 12px;
  margin-bottom: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

/* 尺寸样式 */
.breadcrumb-container.small {
  padding: 12px 16px;
}

.breadcrumb-container.medium {
  padding: 16px 20px;
}

.breadcrumb-container.large {
  padding: 20px 24px;
}

/* 渐变类型 */
.breadcrumb-container.gradient {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.breadcrumb-container.gradient::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 100%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  pointer-events: none;
}

/* 卡片类型 */
.breadcrumb-container.card {
  background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
  border: 1px solid #e6e8eb;
}

/* 现代类型 */
.breadcrumb-container.modern {
  background: white;
  border-radius: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* 图标类型 */
.breadcrumb-container.icon {
  background: linear-gradient(135deg, #ff7e5f 0%, #feb47b 100%);
  color: white;
}

.breadcrumb-container.icon::after {
  content: '';
  position: absolute;
  right: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  background: currentColor;
  opacity: 0.1;
  border-radius: 50%;
}

.breadcrumb-main {
  flex: 1;
}

.beauty-breadcrumb :deep(.el-breadcrumb__item) {
  display: flex;
  align-items: center;
}

.beauty-breadcrumb :deep(.el-breadcrumb__inner) {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.beauty-breadcrumb :deep(.el-breadcrumb__separator) {
  margin: 0 8px;
}

/* 渐变类型样式 */
.breadcrumb-container.gradient .beauty-breadcrumb :deep(.el-breadcrumb__inner) {
  color: rgba(255, 255, 255, 0.9) !important;
}

.breadcrumb-container.gradient .beauty-breadcrumb :deep(.el-breadcrumb__inner:hover) {
  color: #fff !important;
  transform: translateY(-1px);
}

.breadcrumb-container.gradient .beauty-breadcrumb :deep(.el-breadcrumb__separator) {
  color: rgba(255, 255, 255, 0.6) !important;
}

/* 卡片类型样式 */
.breadcrumb-container.card .beauty-breadcrumb :deep(.el-breadcrumb__inner) {
  color: #606266 !important;
  padding: 4px 8px;
  border-radius: 4px;
}

.breadcrumb-container.card .beauty-breadcrumb :deep(.el-breadcrumb__inner:hover) {
  background: rgba(64, 158, 255, 0.1);
  color: #409EFF !important;
}

.breadcrumb-container.card .beauty-breadcrumb :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
  background: #409EFF;
  color: white !important;
}

/* 现代类型样式 */
.breadcrumb-container.modern .beauty-breadcrumb :deep(.el-breadcrumb__inner) {
  color: #606266 !important;
  font-size: 14px;
}

.breadcrumb-container.modern .beauty-breadcrumb :deep(.el-breadcrumb__inner:hover) {
  color: #409EFF !important;
}

.breadcrumb-container.modern .beauty-breadcrumb :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
  color: #303133 !important;
  font-weight: 600;
}

/* 图标类型样式 */
.breadcrumb-container.icon .beauty-breadcrumb :deep(.el-breadcrumb__inner) {
  color: rgba(255, 255, 255, 0.9) !important;
}

.breadcrumb-container.icon .beauty-breadcrumb :deep(.el-breadcrumb__inner:hover) {
  color: white !important;
}

.breadcrumb-container.icon .beauty-breadcrumb :deep(.el-breadcrumb__separator) {
  color: rgba(255, 255, 255, 0.7) !important;
}

.breadcrumb-extra {
  display: flex;
  align-items: center;
  gap: 12px;
}

.breadcrumb-container.gradient .breadcrumb-extra :deep(.el-tag),
.breadcrumb-container.icon .breadcrumb-extra :deep(.el-tag) {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  backdrop-filter: blur(10px);
}

.breadcrumb-container.gradient .breadcrumb-extra :deep(.el-button),
.breadcrumb-container.icon .breadcrumb-extra :deep(.el-button) {
  color: white;
}

.breadcrumb-container.gradient .breadcrumb-extra :deep(.el-button:hover),
.breadcrumb-container.icon .breadcrumb-extra :deep(.el-button:hover) {
  color: #ffd04b;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .breadcrumb-container {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
  
  .beauty-breadcrumb :deep(.el-breadcrumb__item) {
    margin-bottom: 4px;
  }
  
  .breadcrumb-extra {
    width: 100%;
    justify-content: flex-end;
  }
}
</style>